<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;
use app\admin\model\Fields;
/**
 *
 *
 * @icon fa fa-circle-o
 */
class Required extends Backend
{
    public function getProjectRequieredText(\app\admin\model\Project $row) {
        $where['table_name'] = 'project';
        $where['status'] = 1;
        // $where['item_library'] = ['in',"0,{$library_id}"];
        $fields_list = Fields::where($where)->select();

        $required_arr = [];
        foreach ($fields_list as $key => $value) {
            if(isset($row["tmp_{$value['item_id']}"]) && $row["tmp_{$value['item_id']}_status"] == STATUS_SUBMIT)
            {
                // echo $value['item_id'];
                $status ++;
            }

            if(isset($row["tmp_{$value['item_id']}"]) && $row["tmp_{$value['item_id']}_status"] == STATUS_REJECT)
            {
                // echo $value['item_id'];
                $reject_status ++;
            }

            $item_required = $value['item_required'] ? json_decode($value['item_required'],true):'';
            if(isset($row['library_id']) && $row['library_id'] && $item_required )
            {
                $is_required = $item_required[$row['library_id']]['is_required'];

                if($is_required == '1'   && $value['item_class'] != 'capital' && $value['item_class'] != 'agreement')
                {

                    if(!$row[$value['item_id']] && !$row['tmp_'.$value['item_id']])
                        $required_arr[] = $value['item_label'];

                }
            }
        }
        if(!$row['domestic_capital'] && !$row['tmp_foreign_capital'] && !$row['tmp_domestic_capital'] && !$row['foreign_capital'])
            $required_arr[] = '内外资(至少填一项)';



        if(isset($row['library_id']) && $row['library_id']==2)
        {
            if((!$row['carrier_id'] && $row['carrier_id'] != 5 && !$row['carrier_id_relation']) && ($row['tmp_carrier_id'] && $row['tmp_carrier_id'] != 5 && !$row['tmp_carrier_id_relation']))
                $required_arr[] = '载体面积';

            if(($row['is_access'] == '是' &&  !$row['access_time'])|| ($row['tmp_is_access'] == '是' &&  !$row['tmp_access_time']))
                $required_arr[] = '准入时间';
            if(($row['is_land'] == '是' &&  !$row['land_time']) ||  ($row['tmp_is_land'] == '是' &&  !$row['tmp_land_time']))
                $required_arr[] = '拿地时间';

            if(!$row['framework_agreement_time'] && !$row['invesment_agreement_time'] && !$row['tmp_framework_agreement_time'] && !$row['tmp_invesment_agreement_time'])
                $required_arr[] = '框架、正式协议(至少填一项)';
        }

        $required_text = implode(",",$required_arr);
        return $required_text;

    }
}